//
//  randomNum.cpp
//  learnC++
//
//  Created by apple on 2018/5/25.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "randomNum.hpp"
#include <cstdlib>
#include <ctime>
#include <random>


void test_cpp_random(){
    std::random_device rd;
    std::mt19937 mersenne(rd());
    
    std::uniform_int_distribution<> die(1,6);
    
    // Print a bunch of random numbers
    for (int count = 1; count <= 48; ++count)
    {
        std::cout << die(mersenne) << "\t"; // generate a roll of the die here
        
        // If we've printed 6 numbers, start a new row
        if (count % 6 == 0)
            std::cout << "\n";
    }
}

void test_random_num(){
    
//    printf("%u",PRNG());
    
    srand((unsigned)time(0));
    
    printf("rand = %d = %d\n",rand(),(unsigned)time(0));
    
    int i = static_cast<int>(4.6);
    
    printf("kk = %d",i);
}

//事实证明，我们的算法实际上并不是很好，因为我们稍后会讨论。 但它确实有效地说明了PRNG号码生成的原理。
unsigned int PRNG()
{
    // our initial starting seed is 5323
    static unsigned int seed = 5323;
    
    // Take the current seed and generate a new value from it
    // Due to our use of large constants and overflow, it would be
    // hard for someone to casually predict what the next number is
    // going to be from the previous one.
    seed = 8253729 * seed + 2396403;//溢出后导致和之前的数字没有联系
    
    // Take the seed and return a value between 0 and 32767
    return seed  % 32768;
}


